home *** CD-ROM | disk | FTP | other *** search
- Path: news.delphi.com!usenet
- From: JGUILLORY@delphi.com
- Newsgroups: comp.lang.c++
- Subject: U MUST READ THIS!!!!!
- Date: 11 Feb 1996 15:06:10 GMT
- Organization: Delphi Internet Services Corporation
- Message-ID: <4fl0l2$pl1@news1.delphi.com>
- References: <4epbn1$4hq@ixnews7.ix.netcom.com>
- NNTP-Posting-Host: bos1g.delphi.com
-
-
- Quoting jeremyx from a message in comp.lang.c++
- je> Everyone keeps telling me not to use the "goto"
- je> statement,they act like it's the plague! What is wrong with the goto
- je> statement & what can i use in it's place?
-
- Proper structured code needs no GOTO's eg: Consider the following:
- (untested)
-
- #include <stdio.h>
-
- void main(void) {
- FILE *f;
- label E1;
- char command[]="DIR/W";
-
- f = fopen("TEST.BAT","wt");
- if (f==NULL) goto E1;
- fprintf(f,"%s\n",command);
- fclose(f);
- E1:
- }
-
- -- My syntax on the goto / Labels may be off, as I haven't used goto's
- in C/C++ much.... (never needed them....)
-
- The above could be simply re-written as:
-
- #include <stdio.h>
-
- void main(void) {
- FILE *f;
- char command[]="DIR/W";
-
- f = fopen("TEST.BAT","wt");
- if (f!=NULL) {
- fprintf(f,"%s\n",command);
- fclose(f);
- }
- }
-
- Without GOTO's, you have 1 Start, and 1 Stop, and can write a flow-chart
- to match it very easily, with GOTO's you have 1 start, many stop's,
- and a big headache to look at it....
-
- John H. Guillory
- JGuillory@Delphi.Com
-
- Rainbow V 1.17.0 for Delphi - Test Drive
-
-